package main

import (
	"fmt"
	//引入外部第三方开源Redis库
	"github.com/garyburd/redigo/redis"
)



//Redis的数据结构演练


//操作Redis
func main() {
	fmt.Println("连接Redis数据库")
	conn,err := redis.Dial("tcp","127.0.0.1:6379")
	if err!=nil{
		fmt.Println("redis.Dial err=",err)
		return
	}
	defer conn.Close() //关闭连接

	//写入数据
	_,err = conn.Do("Set","name","This is GoLanguage Redis")
	if err!=nil{
		fmt.Println("set err=",err)
		return
	}

	//读取数据
	r,err := redis.String(conn.Do("Get","name"))
	if err!=nil{
		fmt.Println("read err=",err)
		return
	}

	//nameString := r.(string)
	fmt.Println(r)

}